import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: 'index',
    name: 'shouye',
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/rfcwgl/index/index'),
        meta: {
          title: '首页',
          icon: 'index'
        }
      }
    ]
  },
  // 报销
  {
    path: '/baoXiao',
    component: Layout,
    name: 'baoXiao',
    redirect: 'chaiLvFei',
    // alwaysShow: true,
    meta: {
      title: '报销',
      icon: 'baoxiao'
    },
    children: [
      {
        path: 'chaiLvFei',
        name: 'chaiLvFBX',
        component: () =>
          import('@/views/rfcwgl/chaiLvFBX/manage/chaiLvFBXManage/index.vue'),
        meta: {
          title: '差旅费报销',
          icon: 'chailvfei'
        }
      },
      {
        path: 'feiYongBX',
        name: 'feiYongBaoXiao',
        component: () =>
          import('@/views/rfcwgl/feiYongBX/manage/feiYongBFManage/index.vue'),
        meta: {
          title: '费用报销',
          icon: 'feiyongbaoxiao'
        }
      },
      {
        path: 'feiYongJH',
        name: 'feiYongJiHua',
        component: () =>
          import('@/views/rfcwgl/feiYongJH/manage/feiYongJHManage/index.vue'),
        meta: {
          title: '费用计划',
          icon: 'feiyongjihua'
        }
      },
      {
        path: 'chuChaiBZBZ',
        name: 'chuChaiBuZhuBiaoZhun',
        component: () =>
          import(
            '@/views/rfcwgl/chuChaiBZBZ/manage/chuChaiBZBZManage/index.vue'
          ),
        meta: {
          title: '出差补助标准',
          icon: 'buzhu'
        }
      },
      {
        path: 'faPiaoGL',
        name: 'fapiaoguanli',
        component: () =>
          import('@/views/rfcwgl/faPiaoGL/manage/faPiaoGLManage/index.vue'),
        meta: {
          title: '发票管理',
          icon: 'fapiaoguanli'
        }
      }
    ]
  },
  // 借款
  {
    path: '/jiekuan',
    component: Layout,
    redirect: 'loan',
    name: 'jiekuan',
    // alwaysShow: true,
    meta: {
      title: '借还款管理',
      icon: 'jiehuankuan'
    },
    children: [
      {
        path: 'loan',
        name: 'loan',
        component: () =>
          import('@/views/rfcwgl/jieKuan/manage/jieKuanManage/index.vue'),
        meta: {
          title: '借款',
          icon: 'jiekuan'
        }
      },
      {
        path: 'repayment',
        name: 'repayment',
        component: () =>
          import('@/views/rfcwgl/huanKuan/manage/huanKuanManage/index.vue'),
        meta: {
          title: '还款',
          icon: 'huankuan'
        }
      },
      {
        path: 'Setting',
        name: 'Setting',
        component: () =>
          import(
            '@/views/rfcwgl/jieKuanBZSD/manage/jieKuanBZSDManage/index.vue'
          ),
        meta: {
          title: '借款标准设定',
          icon: 'jiekuanbiaozhun'
        }
      }
    ]
  },
  // 字典表
  {
    path: '/dictionary',
    component: Layout,
    name: 'ziDianBiao',
    // alwaysShow: true,
    // meta: { title: '借还款管理', , icon: 'form' },
    children: [
      {
        path: 'Manage',
        name: 'Manage',
        component: () =>
          import('@/views/rfcwgl/ziDianB/manage/ziDianBManage/index.vue'),
        meta: {
          title: '字典表管理',
          icon: 'zidian'
        }
      }
    ]
  },
  // 测试数据
  {
    path: '/Table',
    component: Layout,
    name: 'table',
    redirect: 'cs/table1',
    meta: { title: '表格编辑', icon: 'zidian' },
    children: [
      {
        path: 'cs',
        name: 'cs',
        redirect: 'table1',
        component: () =>
          import('@/views/ceshi/index.vue'),
        meta: {
          title: '测试数据',
          
        },
        children: [
          {
            path: 'table1',
            name: 'table1',
            component: () =>
              import('@/views/ceshi/table1.vue'),
            meta: {
              title: '表格一'
            }
          },
          {
            path: 'table2',
            name: 'table2',
            component: () =>
              import('@/views/ceshi/table2.vue'),
            meta: {
              title: '表格二'
            }
          },
          {
            path: 'table3',
            name: 'table3',
            component: () =>
              import('@/views/ceshi/table3.vue'),
            meta: {
              title: '表格三'
            }
          },
        ]
      }
    ]
  },
  {
    path: '/I',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: {
          title: '测试',
          icon: 'dashboard'
        }
      }
    ]
  }
]

/**
 * asyncRoutes
 * 异步路由   权限加载
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'http://www.liyusoft.com.cn/web/index.html',
        meta: {
          title: '北京利宇',
          icon: 'link'
        }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({
      y: 0
    }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
